/*
 * Main.java
 *
 * Created on 6 March 2006, 11:51
 *
 */

package webTutorial;

import org.apache.lucene.document.Document;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;

import webTutorial.search.Indexer;
import webTutorial.search.SearchEngine;


//http://oak.cs.ucla.edu/cs144/projects/lucene/index.html
public class Main {
    public static void main(String[] args) {
      try {
        Indexer  indexer = new Indexer();
        indexer.rebuildIndexes();
        System.out.println("rebuildIndexes done");

        SearchEngine instance = new SearchEngine();
        TopDocs hits = instance.performSearch("Notre Dame museum");

        System.out.println("Results found: " + hits.totalHits);
        for(ScoreDoc sd:hits.scoreDocs){
            Document doc = instance.getSearcher().doc(sd.doc);
            System.out.println(doc.get("name")
                               + " -- " + doc.get("city")
                               + " (" + sd.score + ")");

        }
        System.out.println("performSearch done");
      } catch (Exception e) {
        System.out.println("Exception caught.\n");
      }
    }
    
}
